package com.example.todolist.service;

import com.example.todolist.mq.TodoEvent;
import com.example.todolist.model.dto.TodoItemDto;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class TodoEventPublisher {

    private final RabbitTemplate rabbitTemplate;

    @Value("${todo.mq.exchange}")
    private String exchangeName;

    @Value("${todo.mq.routing-key}")
    private String routingKey;

    public void publishTodoEvent(String eventType, TodoItemDto todoItem) {
        TodoEvent event = new TodoEvent(eventType, todoItem);
        rabbitTemplate.convertAndSend(exchangeName, routingKey, event);
    }
}